/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package motiveai.factors;

import java.util.Map;
import java.util.HashMap;
import java.util.Iterator;

/**
 *
 * @author oxplay
 */
public class EnvironmentDefinition {
    
    private Map<Integer, EnvironmentSharedData> environmentSharedDataList = new HashMap<Integer, EnvironmentSharedData>();
    private Map<String, FactorBoolean> booleanFactorDefinitions = new HashMap<String, FactorBoolean>();
    private Map<String, FactorInteger> integerFactorDefinitions = new HashMap<String, FactorInteger>();

    public Map<Integer, EnvironmentSharedData> getEnvironmentSharedData() {
        return environmentSharedDataList;
    }

    public EnvironmentSharedData getEnvironmentSharedData(int hashCode){
        return environmentSharedDataList.get(hashCode);
    }
    
    protected EnvironmentSharedData putEnvironmentSharedData(EnvironmentSharedData environmentSharedData){
        return environmentSharedDataList.put(environmentSharedData.getHashCode(), environmentSharedData);
    }
    
    public Environment generateDefaultEnvironment() {
        Environment env = new Environment();
        env.setEnvironmentDefinition(this);
        for (Iterator<String> it = booleanFactorDefinitions.keySet().iterator(); it.hasNext();) {
            String booleanFactorName = it.next();
            env.setBooleanFactor(booleanFactorName, booleanFactorDefinitions.get(booleanFactorName).getDefaultValue());
        }
        for (Iterator<String> it = integerFactorDefinitions.keySet().iterator(); it.hasNext();) {
            String integerFactorName = it.next();
            env.setIntegerFactor(integerFactorName, integerFactorDefinitions.get(integerFactorName).getDefaultValue());
        }
        env.updateData();
        return env;
    }

    public FactorBoolean getBooleanFactorDefinition(String name) {
        return booleanFactorDefinitions.get(name);
    }

    public FactorInteger getIntegerFactorDefinition(String name) {
        return integerFactorDefinitions.get(name);
    }

    /*
     * Set factor Object
     */
    public void setFactorDefinition(String name, AbstractFactor factor) {
        if (factor instanceof FactorBoolean) {
            booleanFactorDefinitions.put(name, (FactorBoolean) factor);
        } else if (factor instanceof FactorInteger) {
            integerFactorDefinitions.put(name, (FactorInteger) factor);
        }
    }
}
